#include "Core.h"

iMMObj::iMMObj(void) {
	s_LiveObjects.push_back(this);
	RefCount = 0;
}

iMMObj::~iMMObj(void) {
	// Empty destructor
}

void iMMObj::MMObjAddRef() {
	++ RefCount;
}

void iMMObj::MMObjRelease() {
	-- RefCount;
	if(RefCount <= 0) {
		s_LiveObjects.remove(this);
		s_DeadObjects.push_back(this);
	}
}

void iMMObj::CollectGarbage() {
	for each(iMMObj* a in s_DeadObjects) {
		delete a;
		s_DeadObjects.remove(a);
	}
	s_DeadObjects.clear();
}

std::list<iMMObj*> iMMObj::s_LiveObjects;
std::list<iMMObj*> iMMObj::s_DeadObjects;